<template>
	<view>

		<van-search ref="search" v-model="value" placeholder="请输入搜索关键词" @search="onSearch" style="width: 100%;" />
		<view class="shangpp">

			<sp class="spp" v-for="item in sousuolite" :key="item.objectId" :goodlist="item"></sp>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				sousuolite: [],
				isoff: true,
				list: [],
				showSearch: true
			}
		},
		mounted() {

		},
		// onLoad(query){
		// 	console.log(query.focus)
		// 	 if (query.focus === 'true') {
		// 	      this.$nextTick(() => {
		// 	        this.$refs.search.focus();
		// 	      });
		// 	    }
		// },
		onShow() {



			if (this.isoff) {


				let url = `/1.1/classes/bscs`
				this.$get(url).then(res => {
					uni.stopPullDownRefresh()
					// console.log(res)
					let {
						results
					} = res
					if (results.length) {
						this.list = res.results

						this.sousuolite = res.results

					}


				})
				this.onoff()
			}
		},

		methods: {
			onoff() {
				this.isoff = false
			},
			onSearch(event) {
				this.sousuolite === ''
				const text = event.detail
				// console.log("我在这",this.value)
				console.log(text, this.list, this.searchedList)
				this.sousuolite = this.list.filter(item => {
					// console.log(item.xiangqing.includes(text))
					if (item.xiangqing) {
					        return item.xiangqing.includes(text);
					    }
					    return false;
					 


				});
				console.log(this.searchedList)
				for (let i = 0; i < this.sousuolite.length; i++) {
					var url =
						`https://r5ctn9z9.lc-cn-n1-shared.com/1.1/classes/bscs?where={"xiangqing":"${this.sousuolite[i].xiangqing}"}`;
					var header = {
						"X-LC-Id": "r5CTN9z96pCW8mI8fx9YxOmw-gzGzoHsz",
						"X-LC-Key": "8gSsl4Sz0ILMiQeMNMA8xQqg",
						'Content-Type': 'application/json'
					};

					uni.request({
						url: url,
						method: 'GET',
						header: header,

						success: function(res) {

							console.log(res)
							var urll = `https://r5ctn9z9.lc-cn-n1-shared.com/1.1/classes/bscs/` + res.data
								.results[0].objectId;

							var data = {
								sou: res.data.results[0].sou + 1
							}
							uni.request({
								url: `https://r5ctn9z9.lc-cn-n1-shared.com/1.1/classes/bscs/` + res
									.data.results[0].objectId,
								method: 'PUT',
								header: header,
								data: data,
								success: function(res) {
									console.log("成功", res)

								},
								fail: function(err) {
									console.log(err)
								}
							})

						}

					})
				}

			}
		}
	}
</script>

<style>
	.shangpp {
		display: flex;
		flex-wrap: wrap;
		align-items: flex-start;
		margin-top: 3vw;
	}

	.spp {
		margin-left: 8px;
		margin-top: 6px;
		box-sizing: border-box;
		flex: 1;
		display: flex;
		width: 40%;
	}

	.spp:last-child {
		margin-right: auto;
	}
</style>